// 此文件是由模板文件 ".dtpl/component/$rawModuleName.ts.dtpl" 生成的，你可以自行修改模板

import { MyComponent, comify, wxp } from 'base'

@comify()
export default class extends MyComponent {
  /**
   * 组件的属性列表
   */
  properties = {
    width: {
      type: String,
      value: '100vw'
    },
    height: {
      type: String,
      value: '100px'
    },
    sid: {
      type: Number,
      value: 0
    }
  }

  /**
   * 组件的初始数据
   */
  data = {
    x: 0,
    start: 0,
  }

  /**
   * 组件属性值有更新时会调用此函数，不需要在 properties 中设置 observer 函数
   */
  onPropUpdate(prop: string, newValue: any, oldValue: any) {

  }

  onTouchStart(e: any) {
    const { touches: [{ clientX }] } = e;
    this.setDataSmart({ start: clientX })
  }

  onTouchEnd(e: any) {
    const { changedTouches: [{ clientX }] } = e
    const { start } = this.data
    const delta = start - clientX
    if (Math.abs(delta) < 10) return
    const x = delta > 40 ? -80 : 80
    this.setDataSmart({ x })
  }

  _delete(e: any) {
    const { currentTarget: { dataset: { sid } } } = e
    wxp.showModal({ title: '提示', content: '是否确定删除？' })
      .then(() => this.triggerEvent('delete', { id: sid }, {}))
      .finally(() => this.setDataSmart({ x: 0 }))
  }
}

